package com.apply.controller;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.apply.Enum.GradeEnum;
import com.apply.entity.ColumnAndValue;
import com.apply.entity.Grade;
import com.apply.entity.Grade_mod;
import com.apply.service.GradeService;
import com.apply.service.Grande_zcService;
import com.apply.tools.zcUtil;

@Controller
@RequestMapping("/GradeController")
public class GradeController {
@Autowired
private GradeService gs;
@RequestMapping(value="/setGrade",method=RequestMethod.GET)
public String setGrade(String gradecode,String instructor,String jobteacher,
		String teacher,String gradeno){
	System.out.println("+++++++++++++++++++++++"+gs.setGrade(gradecode, instructor, jobteacher, teacher, gradeno));
	return "redirect: /apply/AdmGrade";
}
@RequestMapping(value="/openGrade",method=RequestMethod.GET)
public String openGrade(String gradeon){
	gs.setOpenGrade(gradeon);
	List<ColumnAndValue> cvList=new LinkedList<ColumnAndValue>();
	cvList.add(new ColumnAndValue("and", GradeEnum.gradeno, "=", gradeon));
	Grade_mod grade=gs.getGradeBycv(cvList, "").get(0);
	int campusid=grade.getCampusid();
	int coursesid=grade.getCoursesid();
	int GradeCount=gs.getGradeCountBycoursesid(new Integer(coursesid).toString().trim(), new Integer(campusid).toString().trim());
	if(GradeCount<2){
		Grade g=new Grade();
		g.setGradecode(gs.getCodeByGradeon(gradeon));
		g.setTeacher(20);
		g.setInstructor(21);
		g.setJobteacher(22);
		g.setCoursesid(coursesid);
		g.setCampusid(campusid);
		g.setIsdel(1);
		g.setStatus(0);
		for (int i = 0; i < 2-GradeCount; i++) {
           gs.addGrade(g);
		}
	}
	return "redirect: /apply/AdmGrade";
	
}
@RequestMapping(value="/addGrade",method=RequestMethod.GET)
public String addGrade(String xq,String bm,String kc){
	Grade g=new Grade();
	g.setGradecode(gs.getCodeByid(kc));
	g.setTeacher(20);
	g.setInstructor(21);
	g.setJobteacher(22);
	g.setCoursesid(new Integer(kc));
	g.setCampusid(new Integer(xq));
	g.setIsdel(1);
	g.setStatus(0);
	gs.addGrade(g);
	return "redirect: /apply/AdmGrade";
}




}
